package com.careerraiser.testing;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.careerraiser.child.ComparableDog;
import com.careerraiser.child.Dog;

public class testUnModifiableColl {

	public static void main(String[] args) {
		List<Dog> dogList2=new ArrayList<Dog>();
		Dog dog1 =new ComparableDog("1Dog",1);
		Dog dog2 =new ComparableDog("ADog",2);
		Dog dog4 =new ComparableDog("4Dog",4);
		Dog dog3 =new ComparableDog("3Dog",5);
		
		Dog dog41 =new ComparableDog("4Dog1",4);
		
		System.out.println("List add output : "+dogList2.add(dog4));
		System.out.println(dogList2.add(dog2));
		System.out.println(dogList2.add(dog1));
		System.out.println(dogList2.add(dog3));
		System.out.println(dogList2.add(dog41));
		
		List<Dog>dogList3=Collections.unmodifiableList(dogList2);
		for(int i=0;i<dogList3.size();i++){
			// the operation below will result in an exceprion since
			//the list is now unmodifiable.
			//dogList3.remove(i);
		//	System.out.println("removed element at "+i);
		}
		
		//the original list can still be modified... we will remove the elements.
		for(int i=0;i<dogList2.size();i++){
			dogList2.remove(i);
			i--;
			System.out.println("removed element at "+i+1);
		}

	}

}
